using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;
using System.IO;

public partial class PH_DN_sanphamsua : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDDL();
            LoadData();
        }
    }
    private void LoadData()
    {

        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbsanphamDTO sp = tbsanphamBUS.GetByID(id);
            if (sp != null)
            {
                //txt_MaSp.Text = sp.Masp.ToString();
                txt_Tensp.Text = sp.Tensp;
                txt_dacdiem.Text = sp.Dacdiem;
                txt_giaban.Text = sp.Giaban.ToString();

                //txt_soluong.Text = sp.Soluong.ToString();
                //fu_HinhMinhHoa.ImageUrl = "~/Admin/hinhanh/" + sp.Hinhanh;
                ddl_Loai.SelectedValue = sp.Maloaisp.ToString();
                //txt_ngaynhap.Text = sp.Ngaynhapve.ToString();
                //txt_spdacbiet.Text = sp.Spdacbiet.ToString();
                ddl_dn.SelectedValue = sp.Madn.ToString();

            }
        }
        catch
        {
            Response.Redirect("sanphamlist.aspx");
        }




    }
    private void LoadDDL()
    {
        ddl_Loai.DataSource = tbloaisanphamBUS.GETAll();
        ddl_Loai.DataTextField = tbloaispDTOColumn.Tenloaisp.ToString();
        ddl_Loai.DataValueField = tbloaispDTOColumn.Maloaisp.ToString();
        ddl_Loai.DataBind();

        ddl_dn.DataSource = tbdoanhnghiepBUS.GETAll();
        ddl_dn.DataTextField = tbdoanhnghiepDTOColumn.Tendn.ToString();
        ddl_dn.DataValueField = tbdoanhnghiepDTOColumn.Madn.ToString();
        ddl_dn.DataBind();
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        //try
        //{
            tbsanphamDTO sanpham = new tbsanphamDTO();
            sanpham.Tensp = txt_Tensp.Text;
            sanpham.Dacdiem = txt_dacdiem.Text;
            sanpham.Giaban = float.Parse(txt_giaban.Text);
            //sanpham.Soluong = int.Parse(txt_soluong.Text);
            //sanpham.Hinhanh = fu_HinhMinhHoa.text\\;
            sanpham.Maloaisp = int.Parse(ddl_Loai.SelectedValue);
            //sanpham.Ngaynhapve = DateTime.Parse(txt_ngaynhap.Text);
            //sanpham.Spdacbiet = int.Parse(txt_spdacbiet.Text);
            sanpham.Madn = int.Parse(ddl_dn.SelectedValue);
            tbsanphamBUS.Update(sanpham);
            Response.Redirect("sanphamlist.aspx");


            Label_thanhcong.Text = tbsanphamBUS.error;
        //}

        //catch
        //{
        //    Label_thanhcong.Text = tbsanphamBUS.error;
        //    Response.Redirect("sanphamlist.aspx");
    //    //}
    }
}
